
const app = getApp().globalData

import { applyList } from '../../../api/apply'
Page({
  data: {
    isRun : -1,
    list: [],
    finished: false,
    page: 1,
    formMark: false,

    key: '',
    tabIdx: 0,

    type: 0, //是否为管理员
  },
  toggleTab(e) {
    //isRun
    const { idx } = e.currentTarget.dataset
    console.log(e);

    this.data.page = 1
    this.data.finished = false
    this.setData({
      formMark: false,
      list: [],
      isRun: idx
    })
    this.getList()
  },
  onLoad() {
    // this.getUserInfo()
   this.getList()
  },
  onShow() {
    this.getList()
  },
  
  getUserInfo() {
    getuserinfo().then(res=>{
      if(res.status == 1) {
        this.setData({
          type: res.datas.type
        })
      }
    })
  },
  gopage(e) {
    const { kind, id } = e.currentTarget.dataset
    
    console.log(id);
    console.log(list[id]);
    // const url = `/pages/${kind < 3 ? 'index/yyInfo/index' : 'mine/zhangdan/index'}?id=${id}`
    const url = `/pages/mine/zhangdan/index?list=${list[id]}`
    wx.navigateTo({ url })
  },
   goFarmList1(e) {
    //这里我们跳转详情界面
    var that = this
    //拿到点击的index下标
    var index = e.currentTarget.dataset.index
    //将对象转为string
    // console.log('----id-----');
    // console.log(e)
    // console.log(that.data.list[index])
    var queryBean = JSON.stringify(that.data.list[index])
    wx.navigateTo({
      //const url = `/pages/mine/zhangdan/index?list=${list[id]}`
      url: '/pages/mine/zhangdan/index?worker=' + queryBean,
    })
  },
  gopage(e) {
    const {
      url
    } = e.currentTarget.dataset
    wx.navigateTo({
      url
    })
  },
  goFarmList(e) {
    //这里我们跳转详情界面
    var that = this
    //拿到点击的index下标
    var index = e.currentTarget.dataset.index
    //将对象转为string
    //console.log(e)
    // console.log(that.data.list[index])
    var queryBean = JSON.stringify(that.data.list[index])
    wx.navigateTo({
      url: '/pages/index/info/index?worker=' + queryBean,
    })
  },
 
  navTo(e) {
    const { url } = e.currentTarget.dataset
    wx.navigateTo({ url })
  },
  getList() {
    applyList({pageNum: this.data.page, pageSize: 20, isRun:this.data.isRun,title: this.data.key}).then((res) => {
      console.log('--------');
      console.log(res);
      wx.stopPullDownRefresh()
      this.setData({
        formMark: true,
        list: this.data.page > 1 ? this.data.list.concat(res.datas) : res.datas
      })
      if (this.data.list.length >= res.total) {
        this.data.finished = true
      }
    })
  },
  onPullDownRefresh() {
    this.data.finished = false
    this.data.page = 1
    this.getList()
  },
  onReachBottom() {
    if (this.data.finished) {
      return
    }
    this.data.page++
    this.getList()
  },
})